package zhangqi.com.bind_demo;

import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity {
    private Intent intent;
    private MyServiceConn conn;
    PublicBusiness pb;//因为中间人才有牵线方法，所以类型是中间人

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //绑定领导服务
        intent = new Intent(this,LeaderService.class);
        conn = new MyServiceConn();
        bindService(intent,conn,BIND_AUTO_CREATE);
    }
    public void click(View view) {
        //找领导服务，调用服务的办证方法
        pb.qianxian();
        //pb.damajaing();//打麻将不能调用，报错
    }
    class MyServiceConn implements ServiceConnection{
        //连接服务成功，此方法调用
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            pb = (PublicBusiness) service;
        }
        @Override
        public void onServiceDisconnected(ComponentName name) {

        }
    }
}
